<?php /* 
==================================================
TextCMS -- simple plain/text CMS with GPL licence
Mail sending module
(c) 2008, 4X_Pro
Visit us online: http://textcms.ru
==================================================
*/

function sendmail_mime_encode($text,$charset='utf-8') {
         return "=?".$charset."?B?".base64_encode($text)."?=";
}

function sendmail_send($text,$email,$subj,$from,$reply=false,$html=false,$attach=array()) {
  $email=trim($email);
  if (preg_match('/^[a-zA-Z0-9_.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/',$email)) {
    
    $from_email=sendmail_mime_encode($GLOBALS['config']['sitename'].' <'.$from.'>');
    $text=str_replace("\r",'',$text);
    $headers ='From: '.$from."\n";
    $headers.='Date: '.date('r')."\n";
    $headers.="Return-Path: $from\n";
    $headers.="MIME-Version: 1.0\n";
    $headers.="Content-Type: text/plain; charset=utf-8\n";
    $headers.="Content-Transfer-Encoding: 8bit\n";
    $headers.="X-Priority: 3\n";
    $headers.="X-Mailer: PHP/TextCMS mailer\n";
    return mail($email,sendmail_mime_encode($subj),$text,$headers);
  }
}
